<?php

/**
 * This is the model class for table "activity".
 *
 * The followings are the available columns in table 'activity':
 * @property integer $activityId
 * @property string $name
 * @property integer $stunum
 * @property integer $attendnum
 * @property string $content
 * @property string $requirement
 * @property string $addtime
 * @property tinyInt $isclosed 是否关闭
 */
class Activity extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Activity the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'activity';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('name, stunum, attendnum, content, requirement, addtime', 'required'),
			array('stunum, attendnum', 'numerical', 'integerOnly'=>true),
			array('name', 'length', 'max'=>255),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('activityId, name, stunum, attendnum, content, requirement, addtime', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'activityId' => 'Activity',
			'name' => 'Name',
			'stunum' => 'Stunum',
			'attendnum' => 'Attendnum',
			'content' => 'Content',
			'requirement' => 'Requirement',
			'addtime' => 'Addtime',
		);
	}

	public function getConditionNum(){
		$con = array('noCheck'=>0,'passed'=>0,'unPassed'=>0);
		$stuAcs = Stuactivity::model()->findAll('activityId = :a',array(':a'=>$this->activityId));
		foreach($stuAcs as $s){
			
			switch($s->condition){
				// 1 ---- 未审核 2 ---- 未通过 3 --- 已通过
				case 1:$con['noCheck'] += 1;break;
				case 2:$con['unPassed'] += 1;break;
				case 3:$con['passed'] += 1;break;
				
			}
			
		}
		return $con;
	}
	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('activityId',$this->activityId);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('stunum',$this->stunum);
		$criteria->compare('attendnum',$this->attendnum);
		$criteria->compare('content',$this->content,true);
		$criteria->compare('requirement',$this->requirement,true);
		$criteria->compare('addtime',$this->addtime,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}